package edu.suda.xsap.service.impl;

import edu.suda.xsap.dto.CourseDto;
import edu.suda.xsap.dto.convert.CourseConvert;
import edu.suda.xsap.mapper.CourseMapper;
import edu.suda.xsap.service.CourseService;
import edu.suda.xsapadminutils.common.Result;
import edu.suda.xsapadminvo.CourseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {

    @Autowired
    private CourseMapper courseMapper;

    @Autowired
    private CourseConvert courseConvert;

    @Override
    public Result save(@RequestBody CourseVO courseVO) {
        courseMapper.save(courseVO);
        return Result.success();
    }

    @Override
    public Result delete(@RequestBody CourseVO courseVO) {
        courseMapper.delete(courseVO);
        return Result.success();
    }

    @Override
    public Result update(@RequestBody CourseVO courseVO) {
        courseMapper.update(courseVO);
        return Result.success();
    }

    @Override
    public List<CourseDto> findAll() {
        return courseConvert.ToDtoList(courseMapper.findAll());
    }

}
